"""
    异常消息通知模块
"""

import datetime
import os
import time
import traceback

import requests

from conf.config import config, logger


def send_msg_to_wechat(data, url):
    """
    发送消息到企业微信
    :param data: a dict，发送的json数据
    :param url: a string，企业微信群机器人webhook地址，默认发送至开发者的个人群
    :return: None
    """
    headers = {'Content-type': 'application/json'}
    resp = requests.post(url=url, headers=headers, json=data)

    if resp.json().get("errcode") != 0:
        logger.error(resp.text)


def send_text_msg_to_wechat(content, url=config.get("send_message_url").get("url_normal_person")):
    data = {
        "msgtype": "text",
        "text": {
            "content": content
        }
    }

    send_msg_to_wechat(data, url)


if __name__ == '__main__':
    send_text_msg_to_wechat("test")
